import React, { useEffect, useState } from "react";
import { Button, Checkbox, Form, type FormProps, Input, message } from "antd";
import axios from "axios";
import "./index.css";
const Index: React.FC = () => {
  type FieldType = {
    username?: string;
    password?: string;
    remember?: string;
  };
  let [list, setList] = useState<any>([]);
  let [values, setValues] = useState<any>({});
  let [my, setMy] = useState<any>([]);
  const redner = () => {
    axios.post("/api/lt", { params: { values } }).then((resp) => {
      let { code, msg } = resp.data;
      if (code == 200) {
        list.unshift(msg);
      }
    });
  };
  useEffect(() => {
    redner();
  }, []);
  const onFinish: FormProps<FieldType>["onFinish"] = (values) => {
    setValues(values);
    redner();
    my.unshift(values.username);
  };
  const qc = () => {
    setList([]);
    setMy([]);
  };
  return (
    <div className="jqr">
      <h3>
        <img src="https://robohash.org/4444?set=set3" />
        聊天机器人
      </h3>
      <Form
        name="basic"
        labelCol={{ span: 8 }}
        wrapperCol={{ span: 16 }}
        style={{ maxWidth: 600 }}
        initialValues={{ remember: true }}
        onFinish={onFinish}
        autoComplete="off"
      >
        <Form.Item<FieldType>
          label="请输入聊天内容"
          name="username"
          rules={[{ required: true, message: "Please input your username!" }]}
        >
          <Input placeholder="请输入聊天的内容" />
        </Form.Item>

        <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
          <Button type="primary" htmlType="submit">
            发送
          </Button>

          <Button type="primary" onClick={() => qc()}>
            清除
          </Button>
        </Form.Item>
      </Form>
      <div className="ltk">
        <div className="left">
          <h3>你输入的内容区</h3>
          {my.length > 0
            ? my.map((v: any, i: any) => <div>你的输入:{v}</div>)
            : "请输入聊天的内容"}
        </div>
        <div className="right1">
          <h3>自动回复区</h3>
          {list.length > 0
            ? list.map((v: any, i: any) => <div>机器人回复:{v}</div>)
            : "输入的无效"}
        </div>
      </div>
    </div>
  );
};
export default Index;
